//
// Created by xsh on 2025/5/31.
//

#ifndef SAWSYNTH_H
#define SAWSYNTH_H

#include "instrument.h"
#include <jni.h>
class SawSynth: public Instrument {
public:
    const char* name{};
    double frequency = 261.63; //默认c4
    double amp = 1;
    double detune = 0; // in cents 音分
    enum FilterType {LP,HP,BP};
    struct Filter{
        char* type;
        double cutoff;
        double res;
    };

    // 实现接口方法
    double genWave(short* buffer, int numSamples, double phase, double sampleRate) override;
//    void onEvent(const char* eventName, jobject value, JNIEnv* env) override;
    void onEvent(const char* eventName,jint value) override ;
    void onEvent(const char* eventName,jdouble value) override ;

    double processFilter(double sample, double &prevSample1, double &prevSample2);
};
// 导出函数
extern "C" SawSynth* createInstrument();
extern "C" void destroyInstrument(Instrument* inst);

#endif